<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ include file='../Templates/security.jsp' %>
<%@ include file="FuncionesUtilitarias.jsp" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">


<script type="text/javascript">
    function actualizarBotonEsp(valor){
        var id_gen = valor.replace(/\,.+/, '');
        var id_esp = valor.replace(/.+\,/, '');
        var parametros = id_gen+"','"+id_esp;
        document.getElementById('modEspButton').onclick = Function("modificarNovedad('"+parametros+"')");
        document.getElementById('conEspButton').onclick = Function("novedadConsultada('"+parametros+"')");
    }
</script>
<h1 class="title">Gestión de Tipos de Novedad</h1>
<hr>
<p class="meta"></p>
<center>
    <h2>Consultar Tipos de Novedades</h2>
    <br>
    <div id="center">
        <table>
            <tr id="chooseNovGen">
                <td id="label1"><h4><font color="red">*&nbsp;</font>Tipo de Novedad Genérica:</h4></td>
                <td id="dropdown"><select id="novGenChosen" name ="novGenChosen" property="novGenChosen" onchange="setOptions(this.value);">
                        <script type="text/javascript">
                            $.getJSON("listaNovedadesGenericas.do",
                            function(data) {
                                data.namesNG.sort(function(a,b){return ((a.novedad == b.novedad) ? 0 : ((a.novedad > b.novedad) ? 1 : -1 ))});
                                $.each(data.namesNG, function(i,item){
                                    var string = "<option value='"+item.idNovedad+"'>"+item.novedad+"</option>";
                                    $('#novGenChosen').append(string)
                                });
                            });
                        </script>
                        <option value="seleccionar">Seleccionar</option>
                    </select>
                </td>
                <td><img id="conGenButton" src='style/images/detalles.png' alt='Consultar Tipo de Novedad'></td>
                <td><img id="modGenButton" src='style/images/table_edit1.png' alt='Modificar Tipo de Novedad'></td>
            </tr>
            <br>
            <tr>
                <td id="label1"><h4><font color="red">*&nbsp;</font>Tipo de Novedad Específica:</h4></td>
                <td><select id="novEspChosen" name ="novEspChosen" property="novEspChosen" onchange="actualizarBotonEsp(value)">
                        <script type="text/javascript">
                            function setOptions(valor){
                                var id_gen = valor;
                                $.getJSON("listaNovedadesEspecificas.do",{nombre: id_gen},
                                function(data) {
                                    $('#novEspChosen').empty();
                                    data.namesNE.sort(function(a,b){return ((a.novedadEsp == b.novedadEsp) ? 0 : ((a.novedadEsp > b.novedadEsp) ? 1 : -1 ))});
                                    $.each(data.namesNE, function(i,item){
                                        if (i == 0){
                                            actualizarBotonEsp(id_gen+","+item.idNovedadEsp);
                                        }
                                        document.getElementById('novEspChosen').disabled = false;
                                        var string = "<option value='"+id_gen+","+item.idNovedadEsp+"'>"+item.novedadEsp+"</option>";
                                        $('#novEspChosen').append(string);
                                    });
                                    if((document.getElementById('novEspChosen')).options.length == 0){
                                        var string = "<option value='NA'>No Aplica</option>";
                                        $('#novEspChosen').append(string);
                                        document.getElementById('novEspChosen').disabled = true;
                                    }
                                });
                                document.getElementById('modGenButton').onclick = Function("modificarNovedad('"+id_gen+"','-1')");
                                document.getElementById('conGenButton').onclick = Function("novedadConsultada('"+id_gen+"','-1')");
                            }
                        </script>
                        <option value="seleccionar">Seleccionar</option>
                    </select>
                </td>
                <td><img id="conEspButton" src='style/images/detalles.png' alt='Consultar Tipo de Novedad'></td>
                <td><img id="modEspButton" src='style/images/table_edit1.png' alt='Modificar Tipo de Novedad'></td>
            </tr>
        </table>
    </div>
</center>
